<?php
session_start();
include('../classess/db_connection.php');

if (!isset($_SESSION['id'])) {
    header('Location:../index.php');
}
?>
<!DOCTYPE html>
<html lang="en">
    <head>	
        <!-- start: Meta -->
        <meta charset="utf-8">
        <title>Trainee Admin</title>
        <meta name="description" content="">
        <meta name="author" content="">
        <meta name="keyword" content="">
        <!-- end: Meta -->	

        <!-- start: Mobile Specific -->
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <!-- end: Mobile Specific -->

        <!-- start: CSS -->
        <link href="inner_css/bootstrap.min.css" rel="stylesheet">
        <link href="inner_css/style.min.css" rel="stylesheet">
        <link href="inner_css/retina.min.css" rel="stylesheet">
        <link href="inner_css/sc-edge.css" rel="stylesheet">
        <!-- end: CSS -->	

        <!-- The HTML5 shim, for IE6-8 support of HTML5 elements -->
        <!--[if lt IE 9]>
                <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
                <script src="inner_js/respond.min.js"></script>
                <link href="inner_css/ie.css" rel="stylesheet">
        <![endif]-->

        <!--[if IE 9]>
                <link id="ie9style" href="inner_css/ie9.css" rel="stylesheet">
        <![endif]-->

        <!-- start: Favicon Icons  -->	
        <!--<link rel="shortcut icon" href="img/favicon.png">-->
        <!-- end: Favicon Icons -->	

        <script type="text/javascript" src="inner_js/jquery.js"></script>
        <script type="text/javascript" src="inner_js/validate.js"></script>

        <!-- This Script is using for handle browser back button. Starts Here-->

        <script type = "text/javascript" >
            var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
            if (isSafari == true) {
                function preventBack() {
                    window.reload;
                }
                setTimeout("preventBack()", 0);
                window.onunload = function() {
                    null
                };
            }
        </script>
        <!-- This Script is using for handle browser back button. Ends Here-->
    </head>
    <body>
        <!-- start: Header -->
        <div class="navbar">
            <div class="navbar-inner">
                <div class="container">
                    <button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".sidebar-nav.nav-collapse">
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a href="http://rvtraining.net/" target="_blank" class="navbar-brand"><span>RV Training Solutions</span></a>

                    <!-- start: Header Menu -->
                    <div class="nav-no-collapse header-nav">
                        <ul class="nav pull-right">						
                            <!-- start: User Dropdown -->
                            <li class="dropdown">
                                <a class="btn dropdown-toggle" data-toggle="dropdown">
                                    <i class="halflings user white"></i> Training
                                    <span class="caret"></span>
                                </a>
                                <ul class="dropdown-menu">
                                    <?php
                                    if (isset($_SESSION['id'])) {
                                        /*$select = "SELECT * FROM tbl_cart_payment where user_id='" . $_SESSION['id'] . "'";
                                        $query = mysql_query($select) or die(mysql_error());

                                        if (mysql_num_rows($query)) {
                                            while ($row = mysql_fetch_array($query)) {
                                                $select_course = "SELECT * FROM tbl_courses where id='" . $row['course_id'] . "'";
                                                $query_course = mysql_query($select_course) or die(mysql_error());
                                                if (mysql_num_rows($query_course)) {
                                                    while ($row_course = mysql_fetch_array($query_course)) {
                                                        $crs_id = $row_course['id'];
                                                        echo '<li><a href="course_description.php?home=1&c_id=' . $crs_id . '&u_detail='.$row['user_detail_id'].'">' . $row_course['course_name'] . '</a></li>';
                                                    }
                                                }
                                            }
                                            
                                        }*/
                                        
                                        $select = "
SELECT course.`course_name`,`course`.`course_fee`,course.id as course_id,ud.is_ebook,`ebook`.`ebook_name`,ebook.`ebook_fee`,ebook.id as ebook_id,cart.* FROM tbl_cart_payment AS cart
JOIN tbl_user_details AS ud ON ud.id = cart.user_detail_id
LEFT JOIN tbl_courses AS course ON ud.course_id = course.id 
LEFT JOIN  tbl_ebook AS ebook ON ud.course_id = ebook.id 
WHERE cart.user_id= '" . $_SESSION['id'] . "' group by ud.id";
                                        $query = mysql_query($select) or die(mysql_error());
                                        if (mysql_num_rows($query)) {
                                            while ($row = mysql_fetch_array($query)) {
                                                $crs_id = $row['course_id'];
                                                $ebook_id = $row['course_id'];
                                                if($row['is_ebook'] == 0){
                                                    echo '<li><a href="course_description.php?home=1&c_id=' . $crs_id . '&u_detail='.$row['user_detail_id'].'">' . $row['course_name'] . '</a></li>';
                                                }else{
                                                     echo '<li><a href="course_description.php?home=1&e_id=' . $ebook_id . '&u_detail='.$row['user_detail_id'].'">' . $row['ebook_name'] . '</a></li>';
                                                }
                                            }
                                            
                                        }
                                    }
                                    ?>
                                </ul>
                            </li>
                            <li class="dropdown">
                                <a class="btn dropdown-toggle" data-toggle="dropdown">
                                    <i class="halflings user white"></i> <?php echo $_SESSION['user_name']; ?>
                                    <span class="caret"></span>
                                </a>
                                <ul class="dropdown-menu">

                                    <li><a href="<?php echo "../classess/logout.php"; ?>"><i class="halflings off white"></i> Logout</a></li>
                                </ul>
                            </li>
                            <!-- end: User Dropdown -->
                        </ul>
                    </div>
                    <!-- end: Header Menu -->				
                </div>
            </div>
        </div>
        <!-- end Header -->